const game = document.querySelector('.game'),
    sky = document.querySelector('.sky'),
    land = document.querySelector('.land'),
    bird = document.querySelector('.bird'),
    start = document.querySelector('.start');
    wrap = document.querySelector(".wrap-pillar");

var birddown = null

    start.addEventListener('click',function (){
    gamestart();
})

var speed = 5;
var jump = -40;
var creatpillar = null;

function pillarmove(pillar){
    pillar.movetime = setInterval(() =>{
         pillar.style.left = pillar.offsetLeft- 10 +'px';
         if(pillar.offsetLeft<=-52)
         {
             wrap.removeChild(pillar);
         }
    },40);
};

function gamestart(){
    start.style.display = "none";
//       sky移动
        sky.id="donghua";
//    land移动
         sky.id="donghua";
//    下落
    birddown = setInterval(() =>{//计时器
        bird.style.top = bird.offsetTop + speed + "px";
    },40);
//    跳
    document.addEventListener("keydown",function (e) {
        if(e.key==" ")
        {
            //让小鸟跳
            bird.style.top = bird.offsetTop + jump + "px";
        }
    })
//    创建管道
    creatpillar = setInterval(() =>{
    var pillar = document.createElement("div");
    var top = Math.floor(Math.random()*(300 - 60)) +60;
    pillar.className = "zhuzi";
    pillar.innerHTML = '<div class="up" style="top:-' + top + 'px"></div><div class="down" style="height:'+(top-20)+'px"></div>';
    wrap.appendChild(pillar);
    pillarmove(pillar);
},1600);

}
